/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Source;

import java.sql.ResultSet;
import java.util.LinkedList;

/**
 *
 * @author luisfernando
 */
public class Status_DAO {
    
    private String queryBD;
    ConexionDB conexion;
    LinkedList<Status_POJO> listaDetalle = new LinkedList<Status_POJO>();
    ResultSet resultado;

    public Status_DAO(ConexionDB conexion) {
        this.conexion = conexion;
    }

    
    public LinkedList<Status_POJO> obtenerReg(int IdStatus) {
    
    
         queryBD = "SELECT * FROM Status WHERE idStatus = " + IdStatus;
         System.out.println("Query obtener "+queryBD);
          try {
              
            resultado = conexion.getResultSet(queryBD);

            if (resultado.next()) {
                
                Status_POJO status = new Status_POJO();
                
                status.setIdStatus(Integer.parseInt(resultado.getString("IdStatus")));
                status.setNombre(resultado.getString("nombre"));

                listaDetalle.add(status);
                
               

            }

        } catch (Exception ex) {
            
            System.out.println("Error " + ex);
            
        }
        return listaDetalle;
    }
    
    
    public boolean guardarReg(int idStatus, String nombre){
    
        
         queryBD = "INSERT INTO Status (idStatus, nombre) VALUES ("
                                  +idStatus+ ",'" + nombre + "')";
          System.out.println("Query Guardar "+queryBD);
         
        try {
            
            conexion.executeQuery(queryBD);
            return true;
        
        } catch (Exception ex) {
            
            System.out.println("error " + ex);
            return false;
            
        }


    }
    
    
    
    
    public boolean actualizarReg(int idStatus, String nombre){
    
        
             queryBD = "UPDATE Status SET nombre= '" + nombre+ "'"
                     + " WHERE idStatus = " + idStatus;
             
             
              System.out.println("Query update "+queryBD);
       try {
            conexion.executeQuery(queryBD);
            return true;
            //System.out.println ("Update exitoso");

        } catch (Exception ex) {
            System.out.println("Error " + ex);
            return false;
        }
    }
    
     public boolean eliminarReg (int idStatus ){
        
        queryBD = "DELETE FROM Status WHERE idStatus = "+idStatus;
         System.out.println("Query delete "+queryBD);
        try {
            conexion.executeQuery(queryBD);
            return true;

        } catch (Exception ex) {
            System.out.println("Error " + ex);
            return false;
        }
        
    }
}
